/**
 * by samsun
 */

var arrow_length = 8;
var beta = Math.PI / 9; // 初定箭头角度为40度，故一半为20度


function drawLine(startx, starty, endx, endy,ctx,width,height) {
	var pianYiLiang; // 为了算出两中点之间连线没有被模型屏蔽的部分
	var tan_alpha = Math.abs(endy - starty) / Math.abs(endx - startx);
	var flagx=1;
	if (endx-startx!=0)flagx=(endx - startx) / Math.abs(endx - startx);
	var flagy =1 ;
	if (endy-starty!=0)flagy=(endy - starty) / Math.abs(endy - starty);
	if (tan_alpha <= 1) {
		pianYiLiang = tan_alpha * width / 2;
		ctx.strokeStyle = "rgb(0, 0, 0)";
		ctx.lineWidth = 1;
		ctx.beginPath();
		ctx.moveTo(startx + flagx * width / 2, starty + flagy * pianYiLiang);
		ctx.lineTo(endx - flagx * width / 2, endy - flagy * pianYiLiang);
		ctx.stroke();
		drawArrow(startx, starty, endx - flagx * width / 2, endy - flagy
						* pianYiLiang, ctx); // 画箭头
	} else if (tan_alpha > 1) {
		pianYiLiang = height / (2 * tan_alpha);
		ctx.strokeStyle = "rgb(0, 0, 0)";
		ctx.lineWidth = 1;
		ctx.beginPath();
		ctx.moveTo(startx + flagx * pianYiLiang, starty + flagy * height / 2);
		ctx.lineTo(endx - flagx * pianYiLiang, endy - flagy * height / 2);
		ctx.stroke();
		drawArrow(startx, starty, endx - flagx * pianYiLiang, endy - flagy
						* height / 2, ctx);
	}
}

function drawArrow(startx, starty, endx, endy, ctx) {
	var x3, y3, x4, y4;
	var alpha = Math.atan(Math.abs(endy - starty) / Math.abs(endx - startx));
	var flagx=1;
	if (endx-startx!=0)flagx=(endx - startx) / Math.abs(endx - startx);
	var flagy =1 ;
	if (endy-starty!=0)flagy=(endy - starty) / Math.abs(endy - starty);
	x3 = endx - flagx * arrow_length * Math.cos(alpha - beta);
	y3 = endy - flagy * arrow_length * Math.sin(alpha - beta);
	x4 = endx - flagx * arrow_length * Math.cos(alpha + beta);
	y4 = endy - flagy * arrow_length * Math.sin(alpha + beta);
	ctx.strokeStyle = "rgb(0, 0, 0)";
	ctx.fillStyle = "#130c0e";
	ctx.lineWidth = 1;
	ctx.beginPath();
	ctx.moveTo(endx, endy);
	ctx.lineTo(x3, y3);
	ctx.lineTo(x4, y4);
	ctx.moveTo(endx, endy);
	ctx.fill();
	ctx.stroke();
}
function drawModel(startx, starty,ctx,image){     //control model TBD
	   //canvas =  $("#canvas123")[0];
	
	//	var image = new Image();
	//	image.src ='images/modelUnit/start.png';
	//	drawModel(0,0,ctx,image);
		//drawLine(25,25,126,175,ctx);
		//var image2 = new Image();
		//image2.src ='images/modelUnit/finish.png';
		//drawModel(100,150,ctx,image2);
	ctx.drawImage(image,startx,starty,width,height);
	ctx.fillText('开始',startx+width+10,starty+height/2,50); 
}



   
     
	 
	
